//
//  BIDSubPersonalRepairDetailView.m
//  HJGJCommunity
//
//  Created by mal on 2017/6/7.
//  Copyright © 2017年 mal. All rights reserved.
//

#import "BIDSubPersonalRepairDetailView.h"
#import "AppDelegate+StaticMethod.h"
#import "BIDShowPhotoView.h"

@interface BIDSubPersonalRepairDetailView()<BIDShowPhotoViewDelegate>
{
}
@end

@implementation BIDSubPersonalRepairDetailView
@synthesize delegate;

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if(self)
    {
        //[self prepareViewWithDic:dic];
    }
    return self;
}

- (void)prepareViewWithDic:(NSDictionary *)dic
{
    UITapGestureRecognizer *tapGR = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(callHandler:)];
    _phoneLabel.userInteractionEnabled = YES;
    [_phoneLabel addGestureRecognizer:tapGR];
    //
    CGSize screenSize = [UIScreen mainScreen].bounds.size;
    //报修位置
    _houseNameLabel.text = dic[@"repairPlace"];
    //联系方式
    _phoneLabel.text = dic[@"repairTele"];
    //故障类型
    _faultTypeLabel.text = dic[@"repairTypeName"];
    //故障描述
    _contentLabel.text = dic[@"content"];
    CGFloat height = [BIDGlobalMethods getHeightWithString:dic[@"content"] font:_contentLabel.font constraintSize:CGSizeMake(screenSize.width-16*2, MAXFLOAT)];
    _heightForContentConstraint.constant = height;
    [self layoutIfNeeded];
    //故障图片
    NSArray *arr = dic[@"repairFiles"];
    if(arr.count > 0)
    {
        height = [BIDShowPhotoView heightForShowPhotoViewWithImgCount:arr.count andViewWidth:screenSize.width-16*2];
        _heightForShowPhotoViewConstraint.constant = height;
        _heightForContainerViewConstraint.constant = CGRectGetMaxY(_showPhotoView.frame)+8;
    }
    else
    {
        _heightForShowPhotoViewConstraint.constant = 0;
        _heightForShowPhotoViewConstraint.constant = CGRectGetMaxY(_contentLabel.frame)+8;
    }
    CGSize contentSize = _scrollView.contentSize;
    contentSize.height = CGRectGetHeight(_containerView.frame);
    [_scrollView setContentSize:contentSize];
    //
    if(arr.count > 0)
    {
        NSMutableArray *tempArr = [NSMutableArray array];
        for(NSDictionary *subDic in arr)
        {
            NSString *strFilePath = [[NSString alloc] initWithFormat:@"%@/%@", [AppDelegate getPayServerAddr], subDic[@"path"]];
            [tempArr addObject:strFilePath];
        }
        _showPhotoView.delegate = self;
        [_showPhotoView adjustLayoutWithImgPathArr:tempArr];
    }
}

- (void)callHandler:(UITapGestureRecognizer *)tapGR
{
    [delegate callWithPhone:_phoneLabel.text];
}

- (void)showPhotoAtIndex:(NSInteger)index withImgArr:(NSArray *)imgArr
{
    [delegate showPhotoAtIndex:index withImgArr:imgArr];
}

@end
